package broth.gdt;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MapOverlay extends Overlay {
	
	Paint paint;
	Projection projection;
	int lat0 = 0;
	int long0 = 0;
	int lat1 = 0;
	int long1 = 0;
	GeoPoint geo0;
	GeoPoint geo1;
	Point point0;
	Point point1;
	
	// load the two lat-long points
	public MapOverlay(int latitude0, int longitude0, int latitude1, int longitude1) {
		lat0 = latitude0;
		long0 = longitude0;
		lat1 = latitude1;
		long1 = longitude1;
	}
	
	// draw the line between the two lat-long points
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		
		// perform any super class overlay stuff
		super.draw(canvas, mapView, shadow);
		
		// set up the paint to use (opaque red, rounded ends, width 3)
		paint = new Paint();
		paint.setARGB(255, 0, 0, 255);
		paint.setStrokeCap(Paint.Cap.ROUND);
		paint.setStrokeWidth(3);
		paint.setAntiAlias(true);
		
		// create geopoints from the lat-long points
		geo0 = new GeoPoint(lat0, long0);
		geo1 = new GeoPoint(lat1, long1);
		
		// project the geopoints to pixels
		projection = mapView.getProjection();
		point0 = projection.toPixels(geo0, null);
		point1 = projection.toPixels(geo1, null);
		
		// draw the line on the canvas
		canvas.drawLine(point0.x, point0.y, point1.x, point1.y, paint);
	}

}
